package priv.pront.code.lanqiao.competition.course.date0403;

import java.util.Arrays;
import java.util.Scanner;

public class A减B问题 {
    static int N,C,count = 0;
    static int[] arr;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        C = scanner.nextInt();
        arr = new int[N];
        for (int i = 0; i < N; i++) {
            arr[i] = scanner.nextInt();
        }
        Arrays.sort(arr);
        for (int i = N - 1; i >= 1; i--) {
            int left = 0;
            int right = i - 1;
            if(!contains(i,left,right)){
                continue;
            }
//            确认左边界
            int l = getLeft(i, left, right);
//            确认有边界
            int r = getRight(i, left, right);
            count += r - l + 1;
        }
        System.out.println(count);
    }

    private static int getRight (int i, int left, int right) {
        while (left < right) {
            int mid = (left + right + 1) / 2;
            if(arr[i] - arr[mid] >= C){
                left = mid;
            }else{
                right = mid - 1;
            }
        }
        return right;
    }

    private static int getLeft(int i, int left, int right) {
        while (left < right) {
            int mid = left + (right - left) / 2;
            if (arr[i] - arr[mid] <= C) {
                right = mid;
            }else{
                left = mid + 1;
            }
        }
        return left;
    }

    private static boolean contains(int i, int left, int right) {
        while (left <= right) {
            int mid = left + (right - left) / 2;
            if (arr[i] - arr[mid] == C) {
                return true;
            }else if(arr[i] - arr[mid] > C){
                left = mid + 1;
            }else{
                right = mid - 1;
            }
        }
        return false;
    }
}
